package com.game.units {
	import com.game.data.Data;
	
	import flash.display.BitmapData;
	import flash.display.Graphics;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;

	public class EnemyHealth {
		private var _graphics:Graphics;
		private var _offset:int=4;
		public var size:int = Data.STEP;
		public var padding:int=Data.IMAGE_PADDING;
		private var _maxValue:int=0;
		private var _rect:Rectangle=new Rectangle(0,0,size-_offset , 4);
		private var _bmpFill:BitmapData=new BitmapData(size-_offset , 4,false,0xff0000);
		public function EnemyHealth(graphics:Graphics) {
			_graphics = graphics;
			_graphics.lineStyle(0,0);
			_graphics.beginBitmapFill(_bmpFill,new Matrix(1,0,0,1,-(size-_offset)/ 2, -(size+padding) / 2-4),false);
			_graphics.drawRect(-(size-_offset)/ 2, -(size+padding) / 2-4, size-_offset , 4);
			_graphics.endFill();
		}
		public function init(value:int):void{
			_maxValue=value;
			update(_maxValue);
		}
		public function update(value:int):void{
			_bmpFill.fillRect(this._bmpFill.rect,0xff0000);
			_rect.width=(size-_offset)*value/_maxValue;
			_bmpFill.fillRect(_rect,0x00ff00);
		}
	}
}